﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(ApplyMeshTransform))]
public class ApplyMeshTransformEditor : E_ShowButtons<ApplyMeshTransform> { }
#endif
public class ApplyMeshTransform : MonoBehaviour
{
    private MeshFilter mf
    {
        get { return GetComponent<MeshFilter>(); }
    }
    private Mesh mesh
    {
        get { return mf == null ? null : mf.sharedMesh; }
        set { if (mf != null) mf.sharedMesh = value; }
    }
    public float y = 0.5f;
    public string defaultPath = @"Assets\Meshs";
    public bool copyMesh = true;
    [ShowButton]
    void Copy()
    {
        mesh = Instantiate(mesh);
    }
    [ShowButton]
    void Apply()
    {
        if (mesh != null) mf.ApplyScale(copyMesh);
    }
    [ShowButton]
    void Save()
    {
        string filePath = EditorUtility.SaveFilePanelInProject(
            "Save Procedural Mesh", mesh.name, "asset", "select a location to save", defaultPath);
        if (filePath.Length > 0)
            AssetDatabase.CreateAsset(mesh, filePath);
    }
    [ShowButton]
    void SetYTo()
    {
        if (mesh != null) mf.SetYTo(y, copyMesh);
    }
    [ShowButton]
    void SetYToOne()
    {
        if (mesh != null) mf.SetYToOne(copyMesh);
    }
}
